﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using System.ComponentModel;

namespace Milkify.Input
{
    public static class KeyboardShortcutHelper
    {
        private static TypeConverter sGenericKeyGestureConverter = TypeDescriptor.GetConverter(typeof(GenericKeyGesture));

        public static GenericKeyGesture GetKeyGesture(string settingName)
        {
            return GetKeyGesture(settingName, string.Empty);
        }

        public static GenericKeyGesture GetKeyGesture(string settingName, string displayString)
        {
            var settingValue = Properties.Settings.Default[settingName] as string;
            GenericKeyGesture gesture = (GenericKeyGesture)sGenericKeyGestureConverter.ConvertFromString(settingValue);
            return GetKeyGesture(gesture.Key, gesture.Modifiers, displayString);
        }

        public static GenericKeyGesture GetKeyGesture(Key key)
        {
            return GetKeyGesture(key, ModifierKeys.None);
        }

        public static GenericKeyGesture GetKeyGesture(Key key, ModifierKeys modifiers)
        {
            return GetKeyGesture(key, modifiers, string.Empty);
        }

        public static GenericKeyGesture GetKeyGesture(Key key, string displayString)
        {
            return GetKeyGesture(key, ModifierKeys.None, displayString);
        }

        public static GenericKeyGesture GetKeyGesture(Key key, ModifierKeys modifiers, string displayString)
        {
            return new GenericKeyGesture(key, modifiers, displayString);
        }

        public static MultipleInputGesture GetMultipleGesture(params InputGesture[] gestures)
        {
            return GetMultipleGesture(null, gestures);
        }

        public static MultipleInputGesture GetMultipleGesture(EventHandler<MultipleInputGestureEventArgs> eventHandler, params InputGesture[] gestures)
        {
            var multipleGesture = new MultipleInputGesture(gestures);
            if (eventHandler != null)
                multipleGesture.GestureMatched += eventHandler;
            return multipleGesture;
        }
    }
}
